<?php
/**
 * 测试行业选项API
 */
require __DIR__ . '/backend/vendor/autoload.php';

use think\facade\Db;

// 配置数据库连接
Db::setConfig([
    'default' => 'mysql',
    'connections' => [
        'mysql' => [
            'type' => 'mysql',
            'hostname' => '127.0.0.1',
            'database' => 'oa5',
            'username' => 'root',
            'password' => '123456',
            'hostport' => '3306',
            'prefix' => 'oa_',
        ]
    ]
]);

echo "=== 测试 industryOptions API ===\n\n";

try {
    $industries = Db::name('industry')
        ->where('status', 1)
        ->order('id', 'asc')
        ->select();

    echo "查询到的行业数量: " . count($industries) . "\n\n";

    if (empty($industries)) {
        echo "❌ 未查询到任何行业数据！\n";
    } else {
        echo "✅ 行业列表:\n";
        $options = [];
        foreach ($industries as $industry) {
            echo sprintf("  [%d] %s\n", $industry['id'], $industry['title']);
            $options[] = [
                'value' => $industry['id'],
                'label' => $industry['title']
            ];
        }

        echo "\n=== API返回格式 ===\n";
        $response = [
            'code' => 0,
            'data' => $options,
            'message' => 'success'
        ];

        echo json_encode($response, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . "\n";
    }
} catch (Exception $e) {
    echo "❌ 错误: " . $e->getMessage() . "\n";
    echo "错误详情: " . $e->getTraceAsString() . "\n";
}

echo "\n=== 测试完成 ===\n";
